package 力扣日常刷题.木22一月.第06天0114;

import java.util.HashSet;

/**
 * @author 帅小伙
 * @date 2022/1/14
 * @description
 */
public class Demo10回溯中等拆分字符串使唯一子字符串的数目最大 {

    int ans = 0;
    HashSet<String> strings = new HashSet<>();
    public int maxUniqueSplit(String s) {
        dfs(0,s,0);
        return ans;
    }

    void dfs(int index,String s,int count){
        if(index == s.length()) {
            ans = Math.max(ans,count);
            return;
        }

        for (int i = index+1; i <= s.length(); i++) {
            if(!strings.contains(s.substring(index,i))){
                strings.add(s.substring(index,i));
                dfs(i,s,count+1);
                strings.remove(s.substring(index,i));
            }
        }
    }


}
